package com.raccoonagents.tools.cascet2d.util;

import org.lwjgl.input.Mouse;

import com.raccoonagents.tools.cascet2d.model.Vector2f;
/**
 * 
 * @author Kari Kuvaja
 *
 */

public class MouseManager {
	/**
	 * @author Kari Kuvaja
	 */
	public enum MouseState {
		PRESSED, CLICKED, RELEASED, UP,
	}

	private static MouseState leftButtonState = MouseState.UP;
	private static MouseState rightButtonState = MouseState.UP;
	private final static Vector2f mouseCoords = new Vector2f(0.0f,0.0f);
	
	/**
	 * 
	 * @return the mouse screen coords.
	 */
	public static Vector2f getMouseCoords(){
		mouseCoords.x = Mouse.getX();
		mouseCoords.y = Mouse.getY();
		return mouseCoords;
	}
	
	
	/**
	 * 
	 * @return the current MouseState for left mouse button 
	 * @see MouseState
	 */
	public static MouseState getLeftButtonState() {
		if (Mouse.isButtonDown(0)) {
			switch (leftButtonState) {
			case UP:
				leftButtonState = MouseState.CLICKED;
				return leftButtonState;

			case CLICKED:
				leftButtonState = MouseState.PRESSED;
				return leftButtonState;

			}
		}

		if (!Mouse.isButtonDown(0)) {
			switch (leftButtonState) {
			case PRESSED:
				leftButtonState = MouseState.RELEASED;
				return leftButtonState;

			default:
				leftButtonState = MouseState.UP;
				return leftButtonState;
			}
		}

		return leftButtonState;
	}
	/**
	 * 
	 * @return the current MouseState for right mouse button 
	 * @see MouseState
	 */
	public static MouseState getRightButtonState() {
		if (Mouse.isButtonDown(1)) {
			switch (rightButtonState) {
			case UP:
				rightButtonState = MouseState.CLICKED;
				return rightButtonState;

			case CLICKED:
				rightButtonState = MouseState.PRESSED;
				return rightButtonState;

			}

		}

		if (!Mouse.isButtonDown(1)) {
			switch (rightButtonState) {
			case PRESSED:
				rightButtonState = MouseState.RELEASED;
				return rightButtonState;

			default:
				rightButtonState = MouseState.UP;
				return rightButtonState;
			}
		}

		return rightButtonState;
	}


}
